<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('通道列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
<!--        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>渠道编号：</label>
                            <input type="text" name="channelCode"/>
                        </li>
                        <li>
                            <label>接口名称(中文名称）：</label>
                            <input type="text" name="channelName"/>
                        </li>
                        <li>
                            <label>接口状态：</label>
                            <select name="status">
                                <option value="">所有</option>
                                <option value="-1">代码生成请选择字典属性</option>
                            </select>
                        </li>
                        <li>
                            <label>通道用户端显示(0.显示, 1.不显示)：</label>
                            <input type="text" name="channelUsershow"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>-->

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:channel:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:channel:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:channel:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:channel:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:channel:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:channel:remove')}]];
    var controlFlag = [[${@permission.hasPermi('system:channel:control')}]];
    var prefix = ctx + "system/channel";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "通道",
            columns: [{
                checkbox: true
            },
                {
                    field: 'channelId',
                    title: '渠道id',
                    visible: false
                },
                {
                    field: 'channelCode',
                    title: '渠道编号'
                },
                {
                    field: 'channelName',
                    title: '接口名称'
                },
                {
                    title: '通道类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return channelTypesTool(row);
                    }
                },
                // {
                //     field: 'channelTypes',
                //     title: '通道类型'
                // },
                {
                    field: 'channelGateway',
                    title: '通道网关地址'
                },
                {
                    field: 'channelCallbackurl',
                    title: '页面通知地址'
                },
                {
                    field: 'channelNotifyurl',
                    title: '回调地址'
                },
                // {
                //     field: 'channelAppid',
                //     title: 'appid'
                // },
                // {
                //     field: 'channelKey',
                //     title: '商户秘钥'
                // },
                {
                    field: 'channelRate',
                    title: '通道费率'
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '通道状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return channelStatusTool(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '用户端显示',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return userShowTool(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.channelId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + controlFlag + '" href="javascript:void(0)" onclick="editControl(\'' + row.channelId + '\')"><i class="fa fa-warning"></i>风控</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.channelId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 通道类型 */
    function channelTypesTool(row) {
        if (row.channelTypes == 1) {
            return '<a>快捷支付</a> ';
        } else {
            return '<a>未知类型</a>';
        }
    }


    /* 用户端是否显示 */
    function userShowTool(row) {
        if (row.channelUsershow == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableUserShow(\'' + row.channelId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableUserShow(\'' + row.channelId + '\')"></i> ';
        }
    }

    /* 用户端显示启用 */
    function enableUserShow(channelId) {
        $.modal.confirm("确认要在用户端显示此通道吗？", function() {
            $.operate.post(prefix + "/edit", { "channelId": channelId, "channelUsershow": 0 });
        })
    }

    /* 用户端显示关闭 */
    function disableUserShow(channelId) {
        $.modal.confirm("确认要在用户端隐藏此通道吗？", function() {
            $.operate.post(prefix + "/edit", { "channelId": channelId, "channelUsershow": 1 });
        })
    }

    /* 通道状态 */
    function channelStatusTool(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableChannelStatus(\'' + row.channelId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableChannelStatus(\'' + row.channelId + '\')"></i> ';
        }
    }

    /* 通道状态启用 */
    function enableChannelStatus(channelId) {
        $.modal.confirm("确认要启用此通道吗？", function() {
            $.operate.post(prefix + "/edit", { "channelId": channelId, "status": 0 });
        })
    }

    /* 通道状态启用 */
    function disableChannelStatus(channelId) {
        $.modal.confirm("确认要关闭此通道吗？", function() {
            $.operate.post(prefix + "/edit", { "channelId": channelId, "status": 1 });
        })
    }

    /* 通道类型 */
    function editControl(channelId) {
        var url = prefix + '/viewChannelControl/' + channelId;
        $.modal.open("通道风控", url, '800', '600');
    }
</script>
</body>
</html>